//
//  MainTabBarController.swift
//  sinaWeiBo
//
//  Created by Xuwei Yang on 16/8/8.
//  Copyright © 2016年 Xuwei Yang. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //
        let YMMTabBar = InitTabBar()
        YMMTabBar.YMMDelegate = self
        
        YMMTabBar.composeButtonClosure = {[weak self] in
        
            print("执行闭包")
        }
        
        
        setValue(YMMTabBar, forKey: "tabBar")
        
        //添加子控制器
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
    }

    //重载添加控制器函数
    func addChildViewController(childController: UIViewController, imageName:String, title:String) {
        
        //设置图片
        childController.tabBarItem.image = UIImage(named:imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
       
        //设置标题
        //childController.tabBarItem.title = title
        childController.title = title
        
        //修改渲染
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        //设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: UIControlState.Normal)
        
        //设置导航控制器
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

extension MainTabBarController: YMMTabBarDelegate {
    func didSelectedComposeButton() {
        
    }

}
